
my $url;
my $pagetype;
my ($cate1,$cate2,$cate3);
my %type;

open TYPE,"<../../data/product_category";
while(<TYPE>){
	/(\d+) (.+)/;
	$type{$1}=$2;
}
close(TYPE);

open FILE, "<../../data/purged_log";
open OUTPUT, ">../../data/pagetype";
while(<FILE>){
	/\"GET (\S+)\"/;
	$url=$1;
	
	$url =~ /\/([\w\.]+)/;
	$pagetype=$1;
	
	$cate1="";
	$cate2="";
	$cate3="";
	
	if($pagetype eq "login.action" or $pagetype eq "index.action" ){
		$cate1=$pagetype;
		$cate2=$pagetype;
	}elsif($pagetype eq "product" and $url =~ /\/product\/\d+/){
		$url =~ /(\d+)\.html/;
		($cate1,$cate2,$cate3) = split(/ /,$type{$1});
	}elsif($pagetype eq "product" and $url =~ /productCateFilter/){
		$cate1="/product/productCateFilter.action";
		$cate2=$cate1;
	}else{
		my $i = index($url,'?');
		if($i >= 0){
			$cate1=substr($url,0,$i);
		}else{
			$cate1=$url;
		}
		$cate2=$url;
	}
	
	print OUTPUT $url.','.$pagetype.','.$cate1.','.$cate2.','.$cate3."\n";
}

close(FILE);
close(OUTPUT);